<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Info extends API_Controller {


	public function __construct() {
    	parent::__construct();
	}

	public function index(){

		$id = $this->input->post('id');

		$this->load->model('lists');
		$info = $this->lists->get_one($id);

		$data = array();
		if(!empty($info)){
			$this->load->model('like');
			$this->load->model('laud');
			$this->load->model('comment');
			$data = array(
				'id' => $info['id'],
				'title' => $info['title'],
				'intro' => $info['intro'],
				'publish_time' => $info['publish_time'],
				'nick' => $info['nick'],
				'user_pic' => $info['user_pic'],
				'like' => 0,
				'comment' => 0,
				'laud' => 0
			);

			$data['like'] = $this->like->get_num($info['id']);
			$data['laud'] = $this->laud->get_num($info['id']);
			$data['comment'] = $this->comment->get_num($info['id']);
		}

		$this->to_api_message(1, '获取详情信息成功', $data);
	}

	public function laud(){

		$id = $this->input->post('id');
		$user_id =1;

		$this->load->model('laud');
		$insertData = array();
		$insertData = array(
			'list_id' => $id,
			'user_id' => $user_id,
			'laud_time' => date('Y-m-d H:i:s')
		);
		$insert = $this->laud->insert($insertData);

		if($insert_id){
			$this->to_api_message(1, '赞成功');
		}else{
			$this->to_api_message(0, '赞失败');
		}
	}

	public function like(){

		$id = $this->input->post('id');
		$user_id =1;

		$this->load->model('like');
		$insertData = array();
		$insertData = array(
			'list_id' => $id,
			'user_id' => $user_id,
			'like_time' => date('Y-m-d H:i:s')
		);
		$insert = $this->laud->insert($insertData);

		if($insert_id){
			$this->to_api_message(1, '喜欢成功');
		}else{
			$this->to_api_message(0, '喜欢失败');
		}
	}
}